<template>
  <div>
    <div class="new_list" v-if="jurenwu.length > 0">
      <a class="li" v-for="(item,index) in jurenwu" :key="index" :href="'/pages/character_details/main?id='+item.id+''">
        <!-- list_1 -->
        <div v-if="item.list_style=='list_1'">
          <div class="tit_box">
            <span class="tit">{{item.title}}</span>
            <div class="time"><span class="auName">{{item.author}}</span><span>{{item.creat}}</span></div>
          </div>
          <div class="img_box lg mt-1" :style="{backgroundImage:'url(' + item.image[0] + ')'}" v-if="item.image.length>0"></div>
        </div>
        <!-- list_3 -->
        <div v-if="item.list_style=='list_3'">
          <div class="tit_box">
            <span class="tit">{{item.title}}</span>
            <div class="time"><span class="auName">{{item.author}}</span><span>{{item.creat}}</span></div>
          </div>
          <van-row class="mt-1" gutter="4">
            <van-col span="8" v-for="(img,i) in item.image" :key="i">
              <div class="img_box" :style="{backgroundImage:'url(' + img + ')'}"></div>
            </van-col>
          </van-row>
        </div>
        <!-- list_4 -->
        <div v-if="item.list_style=='list_4'">
          <div class="tit_box">
            <span class="tit">{{item.title}}</span>
            <div class="time"><span class="auName">{{item.author}}</span><span>{{item.creat}}</span></div>
          </div>
        </div>
        <!-- list_2 -->
        <van-row gutter="8" v-if="item.list_style=='list_2'">
          <van-col span="16">
            <div class="tit_box">
              <span class="tit">{{item.title}}</span>
              <div class="time"><span class="auName">{{item.author}}</span><span>{{item.creat}}</span></div>
            </div>
          </van-col>
          <van-col span="8">
            <div class="img_box" :style="{backgroundImage:'url(' + item.image[0] + ')'}"></div>
          </van-col>
        </van-row>
      </a>
    </div>
    <div class="nodata" v-else>
      <van-row>
        <van-col span="24">
          <van-icon custom-class="notIOCN" class="notIOCNWarp" name="notes-o" />
          <div class="notTXT">暂无数据</div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>
<script>
import {integral, views} from '../../utils/utils.js'
export default {
  onShareAppMessage (res) {
    if (res.from === 'button') {
      // 增加积分
      this.sharpePage(this.$root.$mp.query.id, 3)
    } else {
      this.sharpePage(this.$root.$mp.query.id, 4)
    }
    return {
      title: '本真人物',
      imageUrl: '/images/a.png',
      path: '/pages/character_list/main'
    }
  },
  onPullDownRefresh () {
  },
  onReachBottom () {
    let page = this.page + 1
    this.getList(page, this.pagesize)
  },
  data () {
    return {
      jurenwu: [], // 本真人物文章
      page: 1,
      pagesize: 5
    }
  },
  components: {
  },
  methods: {
    // 积分增加， 更新 分享、浏览 、转发数量，增加积分
    // type:share 更新分享数   views  更新浏览数 forwarding 更新转发数
    getIntegral (type = 2) {
      let _this = this
      let id = _this.$root.$mp.query.id
      // 增加积分
      integral(id, type)
      // 增加统计数量  views
      views(id, 'views')
    },
    // 1.签到 2.阅读文章 3.转发文章 4.分享小程序
    sharpePage (id, type = 3) {
      // 增加积分
      integral(id, type)
      // 增加统计数量 share
      views(id, 'share')
    },
    getList (page = this.page, pagesize = this.pagesize) {
      let _this = this
      wx.request({
        url: this.apiUrl + 'api/article?type=jurenwu&page=' + page + '&pagesize=' + pagesize,
        success (res) {
          let data = res.data
          if (data.code === 200) {
            wx.stopPullDownRefresh()
            if (page > 1) {
              // 数据追加
              _this.jurenwu.push(...data.data)
              _this.page = _this.page + 1
            } else {
              _this.jurenwu = data.data
            }
          }
        }
      })
    }
  },
  mounted () {
    this.getList()
  },
  created () {}
}
</script>
<style>
van-row{ display:block;}
</style>
